$(document).ready(function() {
	//获取信息列表
	var userId=getvl("userId");
	$("#thislist").html("");
	$.ajax({
		url: urlcore + "/api/withdrawMesg/detailsByUserId?userId="+userId,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				//i表示在data中的索引位置，n表示包含的信息的对象
				$.each(data.data,function(i,n){	
					var thislist = 
					'	<tr>'+				
					'		<td>'+(i+1)+'</td>'+
					'		<td>'+n.bankNum+'</td>'+
					'		<td>'+n.realName+'</td>'+						
					'		<td>'+n.bankName+'</td>'+
					'		<td>'+n.obligateMobile+'</td>'+					
					'		<td>'+
					'           <a class="btn btn-primary btn-xs" href="javascript:;" data-toggle="modal" data-target="#update" onclick="thisUpdate('+n.id+')"> 修改</a>'+
					'		</td>'+					
					'	</tr>';
					$('#thislist').append(thislist);	
														
				});
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				if (data.msg != '空数据') {
					alert(data.msg)
				}else{
					$('#thiscount').text(0);
				}
			}

		},
		error:function() {
			alert("error");
		}
	});			
});
	
//修改
function thisUpdate(id) {
	$.ajax({
		url: urlcore + "/api/withdrawMesg/detailsById?id="+id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success:function(data){
			if (data.success == true) {
				var da = data.data;
				$('#id_update').val(da.id);
				$('#bankNum_update').val(da.bankNum);
				$('#realName_update').val(da.realName);
				$('#bankName_update').val(da.bankName);
				$('#obligateMobile_update').val(da.obligateMobile);
			} else if (data.code == 'OVERTIME'){
				var thisUrl = window.location.href;
				if (thisUrl.indexOf('login.html') <= -1) {
					top.window.location.href="login.html";
				}

			} else {
				alert(data.msg);
			}

		},
		error:function() {
			/* Act on the event */
			alert("error");
		}
	});	
}

function toUpdate() {
	var id = $('#id_update').val();
	var bankNum = $('#bankNum_update').val();
	var realName = $('#realName_update').val();
	var bankName = $('#bankName_update').val();
	var obligateMobile = $('#obligateMobile_update').val();
	$.ajax({
        url:  urlcore + "/api/withdrawMesg/update?id="+id+"&bankNum="+bankNum+"&realName="+realName+"&bankName="+bankName+"&obligateMobile="+obligateMobile,
       		type: "post",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if (data.success == true) {             
                    if (confirm("修改成功!")) {
                         window.location.reload();
                    } 	                   
                }
             else if (data.code == 'OVERTIME') {
                var thisUrl = window.location.href;
                if (thisUrl.indexOf('login.html') <= -1) {
                    top.window.location.href = "login.html";
                }
            } else {
                alert(data.msg);
            }

        },
        error: function() {
            alert("error");
        }

    });
}
